package com.team.employment.web.admin.schedule;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.team.employment.model.entity.RecruitmentInfo;
import com.team.employment.model.enums.ActiveStatus;
import com.team.employment.model.enums.BaseStatus;
import com.team.employment.model.enums.ReleaseStatus;
import com.team.employment.web.admin.service.RecruitmentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/*
    简历失效时间定时检查
        判断招聘时间是否过期，过期就更新is_active的值为0；
 */
@Component
public class ScheduleTasks {

    @Autowired
    private RecruitmentInfoService recruitmentInfoService;

    @Scheduled(cron = "0 0 0 * * *")
    public void checkRecruitmentActiveStatus(){
        LambdaUpdateWrapper<RecruitmentInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.le(RecruitmentInfo::getEndDate,new Date())
                .eq(RecruitmentInfo::getIsRelease, ReleaseStatus.RELEASED)
                .eq(RecruitmentInfo::getStatus, BaseStatus.ENABLE)
                .set(RecruitmentInfo::getIsActive,ActiveStatus.noActive);
        recruitmentInfoService.update(updateWrapper);
    }

}
